// 员工模块
import request from '@/utils/request'
/**
 * 获取员工列表数据
 * @param {Object} params {page:1,size:100}
 * @returns
 */
export function getEmployeeList(params) {
  return request({
    url: '/sys/user',
    params
  })
}
/**
 * 删除员工
 * @param {String} id 员工id
 * @returns
 */
export const delEmployee = (id) => {
  return request({
    method: 'DELETE',
    url: `/sys/user/${id}`
  })
}
/**
 * 新增员工
 * @param {Object} data {name:'张三',mobile:'16722222222'}
 * @returns
 */
export function addEmployee(data) {
  return request({
    method: 'POST',
    url: '/sys/user',
    data
  })
}

/**
 * 批量导入
 * @param {Array} data 数组对象 [{name:'张三',mobile:'16722222222'},{name:'李四',mobile:'17822222222'}]
 * @returns
 */
export function addEmployeeBatch(data) {
  return request({
    method: 'POST',
    url: '/sys/user/batch',
    data
  })
}
/**
 * 获取员工详情数据
 * @param {String} id 员工id
 * @returns
 */
export function getPersonalDetail(id) {
  return request({
    url: `/employees/${id}/personalInfo`
  })
}

/** *
 *
 * 保存员工的基本信息
 * **/
export function saveUserDetailById(data) {
  return request({
    url: `/sys/user/${data.id}`,
    method: 'put',
    data
  })
}
/**
 * 更新员工的详细信息
 * @param {Object} data
 * @returns
 */
export function updatePersonal(data) {
  return request({
    url: `/employees/${data.userId}/personalInfo`,
    method: 'PUT',
    data
  })
}
/** **
 * 获取用户的岗位信息
 *
 * ****/
export function getJobDetail(id) {
  return request({
    url: `/employees/${id}/jobs`
  })
}

/**
 * 保存岗位信息
 * ****/
export function updateJob(data) {
  return request({
    url: `/employees/${data.userId}/jobs`,
    method: 'put',
    data
  })
}
/**
 * 给用户分配角色
 * @param {Object} data {id:1,roleIds:[1,2,3,4]}
 * @returns
 */
export function assignRoles(data) {
  return request({
    method: 'PUT',
    url: '/sys/user/assignRoles',
    data
  })
}
